﻿//using System;
//using System.Collections.Generic;
//using System.Globalization;
//using System.Reflection;
//using System.Security;

//namespace MVCBootstrap.MongoDB.Localization {

//    public class MongoTextManager : TextManager {
//        /// This delegate is used to resolve the current language;
//        /// </summary>
//        public Func<LanguageInfo> CurrentLanguage;

//        public Func<TimeZoneInfo> CurrentTimeZone;

//        public Func<IMongoCollection<TextChunk>> Collection;

//        /// <summary>
//        /// The function used to write debug information about texts. If null default behavior is used.
//        /// Arguments: Namespace, Key, Language, Mathing text (if any), the parameters for the text
//        /// </summary>
//        public Func<String, String, LanguageInfo, LocalizedTextCacheEntry, ParameterSet, String> DebugFormatter { get; set; }

//        /// <summary>
//        /// If this is specified and returns true debug information about the texts will be returned. (See DebugFunction).
//        /// </summary>
//        public Func<Boolean> DebugMode;

//        private Dictionary<CultureInfo, LanguageInfo> _languageInfoCache = new Dictionary<CultureInfo, LanguageInfo>();

//        public MongoTextManager()
//            : base() {

//            CurrentLanguage = () => {
//                LanguageInfo languageInfo;
//                var culture = CultureInfo.CurrentUICulture;
//                if (!_languageInfoCache.TryGetValue(culture, out languageInfo)) {
//                    _languageInfoCache.Add(culture, languageInfo = (LanguageInfo)culture);
//                }
//                return languageInfo;
//            };

//            CurrentTimeZone = () => TimeZoneInfo.Local;

//            //Build-in texts            
//            FallbackNamespaces.Add(GetNamespace<DefaultTextManager>());

//            //Empty namespace
//            FallbackNamespaces.Add("");

//            // This is used to match texts that all languages should fall back to
//            FallbackLanguages = new List<LanguageInfo> { new LanguageInfo { Key = "*" } };
//        }

//        public override String GetNamespace(Assembly asm) {
//            try {
//                return asm.GetName().Name;
//            }
//            catch (SecurityException) {
//                return asm.FullName;
//            }
//        }


//        /// <summary>
//        /// If the calling assemblies' name are used as namespace for keys
//        /// </summary>
//        public Boolean UseNamespaces { get; private set; }


//        public Dictionary<String, LanguageInfo> Languages { get; set; }


//        /// <summary>
//        /// Enables the Html tags in patterns using the default dialect. 
//        /// It will change the syntax for format groups from "&lt;Group: ... &gt;" to "&lt;!Group: ... &gt;"
//        /// </summary>
//        /// <returns></returns>
//        public MongoTextManager EnableHtmlPatterns() {
//            Dialects["Default"].PatternTransformer = new HtmlPatternTransformer();
//            return this;
//        }


//        protected override Boolean IsInDebugMode() {
//            return DebugMode != null ? DebugMode() : base.IsInDebugMode();
//        }

//        protected override String DebugText(String ns, String key, LanguageInfo language, ParameterSet dict) {
//            if (DebugFormatter != null) {
//                var text = GetTextEntry(ns, key, language, true);
//                return DebugFormatter(ns, key, language, text, dict);
//            }

//            return base.DebugText(ns, key, language, dict);
//        }

//        public void GetTexts(Func<IMongoCollection<TextChunk>> collection) {
//            this.Texts.Sources.Add(new PrioritizedTextSource(new MongoTextSource(collection)));
//        }

//        protected override void SourceTextsChanged(Object sender, EventArgs args) {
//            base.SourceTextsChanged(sender, args);
//        }

//        public override LanguageInfo GetCurrentLanguage() {
//            return this.CurrentLanguage();
//        }

//        public override TimeZoneInfo GetCurrentTimeZoneInfo() {
//            return this.CurrentTimeZone();
//        }
//    }
//}